Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add/remove reaction #15210

Merged

Conversation

hannojg
Copy link
Contributor

@hannojg hannojg commented Feb 16, 2023

Details

Implementation for adding and removing reactions, according to:

Known issues:

  • When sending reactions very rapidly it can happen that a pusher event with stale information overwrites the local state, and thus causing buggy behaviour. This is a known issue with the current architecture. See this video for an example of the bug: https://user-images.githubusercontent.com/16821682/222969430-873513c0-63d5-4a84-95f5-72a13377762e.mov

  • When editing a message the reactions will get removed. Here pusher sends an event where the reactions property in the message object is missing. This needs to be fixed elsewhere I believe.

(Done) TODO:

Fixed Issues

$ #15125
PROPOSAL: GH_LINK_ISSUE(COMMENT)

Tests

Quick reactions are working

Test 1: Web specific, hover menu:

  • Login with user A
  • Open a chat with user B
  • Send a message
  • Hover over the send message with the mouse
  • Expect the context menu to show in the top right corner, and it shows the four quick reaction emojis as well as a icon button to open the emoji picker
  • When pressing on the "👍" reaction, the "👍" gets added as reaction to the message
  • When pressing the "👍" in the menu again the reaction gets removed

Test 2: Quick reactions from context menu

  • Login with user A
  • Open a chat with user B
  • Send a message
  • When right pressing (on web/desktop), or long pressing (mobile) the context menu opens
  • When pressing on the "👍" reaction, the "👍" gets added as reaction to the message
  • The context menu closes after pressing the reaction
  • Open the context menu again and press the "👍" in the menu again -> the reaction gets removed

The emoji picker is working

Test 1: Web specific, hover menu:

  • Login with user A
  • Open a chat with user B
  • Send a message
  • Hover over the send message with the mouse
  • Expect the context menu to show in the top right corner, and it shows the four quick reaction emojis as well as a icon button to open the emoji picker
  • Press the icon button with the emoji to open the emoji picker
  • Expect the hover menu to stay open while the emoji picker opens next to the icon button
  • When selecting an emoji it gets added to the message as reaction
  • Upon selecting an emoji the emoji picker closes
  • When opening the emoji picker again and pressing the same emoji again it gets removed from the message

Test 2: Emoji picker from context menu

  • Login with user A
  • Open a chat with user B
  • Send a message
  • When right pressing (on web/desktop), or long pressing (mobile) the context menu opens
  • Press the icon button with the emoji to open the emoji picker
  • Expect the context menu to dismiss and instead the emoji picker shows
  • When selecting an emoji it gets added to the message as reaction
  • Upon selecting an emoji the emoji picker closes
  • When opening the emoji picker again and pressing the same emoji again it gets removed from the message

Test 3: Emoji picker from reactions

  • Login with user A
  • Open a chat with user B
  • Send a message
  • Add a reaction by either using the picker or quick reactions, doesn't matter
  • Expect that next to the reaction that now shows underneath the message a "add emoji" icon button appeared
  • When pressing it expect the emoji picker to open
  • When selecting an emoji it gets added to the message as reaction
  • Upon selecting an emoji the emoji picker closes
  • When opening the emoji picker again and pressing the same emoji again it gets removed from the message

📩 Sending & receiving works

  • Login with user A on device A
  • Login with user B on device B
  • User A sends a chat message to user B
  • User B reacts with a 👍 (👍) to the message of user A
  • Both user A and user B can see the reaction on the message user A sent
  • For user B the reaction underneath the message is highlighted (so it's obvious to user B that he/she added the reaction)
  • User A now reacts as well with a 👍
  • For both users the reaction counter increments to 2
  • Both users now remove their reaction
  • For both users the reaction is gone
  • User A now adds another emoji reaction, which isn’t the 👍 (e.g. 😊 😊)
  • After that User B now adds again a 👍 reaction
  • We confirm that for both users the 👍 reaction is after the 😊 reaction user A sent (chronological order)

Adding the same reaction twice with different skin tone

  • Login with user A
  • Open a chat with user B
  • Send a message
  • Add a "👍" as reaction
  • Now open the emoji picker for adding a reaction
  • Change the default skin color to something else than the yellow tone
  • Add the "👍" emoji again but this time with the different skin tone
  • Verify that the reaction bubble underneath the message now shows both emoji skin tones and the counter says "2". Also make sure that the emoji appear in the correct order (e.g. first the yellow one, then the one with the skin tone that you picked)

Offline tests

  • Login with user A on device A
  • Login with user B on device B
  • User A sends a chat message to user B
  • After user B receives the message
  • Put the device of user B offline
  • User B reacts with a 👍 to the message of user A
  • User B sees the reaction immediately, while user A doesn't yet
  • User B goes online again
  • User A receives the emoji reaction User B sent

QA Steps

See testing steps above

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
web.mov
Mobile Web - Chrome
Screen.Recording.2023-02-19.at.16.48.58.mov
Mobile Web - Safari
Simulator.Screen.Recording.-.iPhone.14.-.2023-02-19.at.16.45.56.mp4
Desktop
desktop.mov
iOS
Simulator.Screen.Recording.-.iPhone.14.-.2023-02-19.at.16.47.24.mp4
Android
Screen.Recording.2023-02-19.at.16.55.13.mov

@hannojg hannojg marked this pull request as ready for review February 19, 2023 16:16
@hannojg hannojg requested a review from a team as a code owner February 19, 2023 16:16
@melvin-bot melvin-bot bot removed the request for review from a team February 19, 2023 16:17
Copy link
Contributor

@stitesExpensify stitesExpensify left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and tests well 🎉 LET'S DO THIS!

@stitesExpensify
Copy link
Contributor

Waiting for verify_podfile....

@stitesExpensify stitesExpensify merged commit f4ffc7c into Expensify:main Mar 8, 2023
@OSBotify
Copy link
Contributor

OSBotify commented Mar 8, 2023

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@0xmiros
Copy link
Contributor

0xmiros commented Mar 8, 2023

Simulator Screen Shot - iPhone 14 Pro Max - 2023-03-08 at 15 05 21

Sorry, let's fix this quickly in new PR. Happens after log out

Comment on lines +82 to +85
// make sure that renderContent isn't mixed with unsupported props
if (__DEV__ && (contextAction.text != null || contextAction.icon != null)) {
throw new Error('Dev error: renderContent() and text/icon cannot be used together.');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also remove this dev code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly I think this is a good warning to have, I wouldn't mind keeping it

@0xmiros
Copy link
Contributor

0xmiros commented Mar 8, 2023

While digging into above console warning, I found performance issue on main (before this PR).
BaseReportActionContextMenu component is rendered unnecessarily on app launch (even when logged out).
This happens because of this code:

App/src/Expensify.js

Lines 203 to 205 in f4ffc7c

<PopoverReportActionContextMenu
ref={ReportActionContextMenu.contextMenuRef}
/>

@0xmiros
Copy link
Contributor

0xmiros commented Mar 8, 2023

@stitesExpensify I think it would be good to announce in channel about known issues we discussed in this PR so that contributors or QA team won't do duplicated bug report which we are already aware of and planned to fix.

@perunt perunt mentioned this pull request Mar 8, 2023
55 tasks
@OSBotify
Copy link
Contributor

OSBotify commented Mar 9, 2023

🚀 Deployed to staging by https://github.com/stitesExpensify in version: 1.2.81-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

throw new Error('Dev error: renderContent() and text/icon cannot be used together.');
}

return contextAction.renderContent(closePopup, payload);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will prefer the following pattern instead of renderContent if there are no hidden tricks.

  1. If you want the user to provide UI instead of rendering the default UI via ContextMenuItem.
  2. Then we can accept a functional Component instead of Object in ContextMenuActions.
  3. It means that the first act of ContextMenuActions you added in this PR can simply be a functional component that will accept all the values as props.

This will also remove the possibility of user error where the user can provide text or icon and renderContent together.

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/roryabraham in version: 1.2.81-1 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

<Pressable
style={({hovered}) => [
styles.emojiReactionBubble,
StyleUtils.getEmojiReactionBubbleStyle(hovered, hasUserReacted, props.sizeScale),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pressed state styles were missed here. #15813

@puneetlath
Copy link
Contributor

Friendly FYI: this PR created a very small regression in the copy: #15867. Should've been Edit reaction instead of Edit Reaction in order to be consistent with how we do it everywhere else in the app.

@stitesExpensify
Copy link
Contributor

Ach dangit. Thanks for letting me know

@sobitneupane
Copy link
Contributor

This PR created a regression: #16384. On navigation to Add reaction bubble using keyboard, the emoji picker appears in top left corner.

@sobitneupane
Copy link
Contributor

With this PR, we have updated the size of emoji in reaction of a message to 28px with a font size of 15px, in mini context menu to 20px with a font size of 13px and in context menu to 34px with a font size of 17px.

Those changes might have been missed or not considered in this PR.

hovered,
pressed,
}) => [
styles.emojiReactionBubble,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should prevent selection on all buttons where long-press action is supported as it moves the selection around the UI on safari iOS.
#18661

ref={props.innerRef}
focusable
onPress={props.onPress}
accessibilityLabel={props.tooltipText}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming from #33547, we should add prop role={CONST.ROLE.BUTTON} if the Pressable is a button/icon button to avoid text selection issue on double click.

Copy link
Member

@rushatgabhane rushatgabhane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.